<template>
	<view class="content">
		<loading v-if="showLoading"></loading>
		<CustomNav title="积分商城" :normal="{textColor:'#fff',background:'linear-gradient(to right,#FF3432, #FF671A)'}"
			:is-back="true"></CustomNav>
		<view class="search-block">
			<view class="search-item">
				<view class="input-block">
					<view class="input-left">
						<image
							src="https://job-1306862033.cos.ap-chengdu.myqcloud.com/miniprogram-static/alliance/search.png"
							mode=""></image>
						<input placeholder="请输入关键字" v-model="conf.name" @confirm="getMap()" />
					</view>
					<view class="search" @click="search">搜索</view>
				</view>
			</view>
		</view>
		<view class="info-block">
			<template v-if="list.length>0">
				<view class="list-block">
					<view class="info-list" v-for="(item,index) in list" :key="item.id"
						@click="navigate('/page_other/integral/detail?id='+item.id)">
						<view class="info-item">
							<image :src="cloudStorage+item.goodsFace" class="img" mode="aspectFill"></image>
							<view class="describe-item">
								<view class="name">{{item.name}}</view>
								<view class="describe">{{item.label}}</view>
								<view class="wage">￥{{item.integral}}积分+{{item.voucher}}券</view>
							</view>
						</view>
					</view>
				</view>
			</template>
			<view v-if="more==false&&list.length==0" class="empty">暂无数据</view>
			<view v-else-if="more==false&&list.length>0" class="empty">没有更多了</view>
		</view>
	</view>
</template>

<script>
	import {
		isMore
	} from '@/util/util.js'
	import {
		getStorage
	} from '@/util/auth.js';
	import {
				getUserGoodsList,
	} from '@/api/integral.js'
	export default {
		data() {
			return {
				conf: {
					page: 1,
					limit: 10,
					name: '',
					applyType:1
				},
				more: true,
				list: []
			}
		},
		watch: {
			mallType: {
				handler() {
					this.getList(true)
				}
			}
		},
		methods: {
			search() {
				this.getList(true)
			},
			handleRefresh() {
				this.conf.page = 1;
				this.more = true
				uni.showLoading({
					title: '加载中',
					mask: true
				})
				this.getList(true)
			},
			getTabList() {
				return getCategoryApi({
					code: 'SHOPING_TYPE'
				}).then(data => {
					this.tabList = data
				})
			},
			getList(refresh = false) {
				return getUserGoodsList(this.conf).then((res) => {
					let list = res.list || [];
					if (refresh) {
						this.list = list;

					} else {
						this.list = [...this.list, ...list]
					}
					this.more = isMore(this.conf.page, this.conf.limit, res.count)
				})
			}
		},
		onPullDownRefresh() {
			this.handleRefresh();
		},
		onReachBottom() {
			if (this.more) {
				this.conf.page++;
				uni.showLoading({
					title: '加载中',
					mask: true
				})
				this.getList();
			}
		},
		async onLoad(e) {
			if(e.applyType)
			{
				this.conf.applyType=e.applyType
			}
			uni.showCustomLoading();
			Promise.all([this.getList(true)]).finally(() => {
				uni.hideCustomLoading()
			})
		}
	}
</script>

<style lang="scss" scoped>
	.content {
		width: 100%;
		//height: calc(100vh - 160rpx);
		overflow-y: auto;
		position: relative;

		.search-block {
			width: 100%;
			height: 200rpx;
			margin-top: 180rpx;
			background-image: linear-gradient(to right, #FF3432, #FF671A);
			padding: 30rpx;
		}

		.search-item {
			width: 100%;
			height: 70rpx;
			display: flex;


			.address-block {
				display: flex;
				background-color: #FFFFFF;
				align-items: center;
				justify-content: center;
				width: 130rpx;
				border-radius: 50px;
				margin-right: 20rpx;

				image {
					width: 30rpx;
					height: 30rpx;
					margin-right: 5rpx;
				}

				.address {
					color: #FF2F34;
					font-size: 28rpx;
				}
			}

			.input-block {
				display: flex;
				background-color: #FFFFFF;
				border-radius: 50px;
				align-items: center;
				justify-content: space-between;
				width: 100%;
				padding: 6rpx 6rpx 6rpx 20rpx;

				.input-left {
					width: calc(100% - 140rpx);
					display: flex;

					image {
						width: 30rpx;
						height: 30rpx;
						// margin-right: 5rpx;
						margin: 7rpx 7rpx 0 0;
					}

					input {
						border-radius: 50px;
						width: 100%;

					}
				}

				.search {
					display: flex;
					justify-content: center;
					align-items: center;
					width: 130rpx;
					border-radius: 50rpx;
					height: 100%;
					padding-bottom: 5rpx;
					color: #FFFFFF;
					background: linear-gradient(90deg, #FF2F34 0%, #FF6B18 100%);
				}
			}
		}


		.info-block {
			display: flex;
			flex-direction: column;
			background: #F5F9FC;
			border-radius: 40rpx;
			margin-top: -50rpx;
			height: auto;
			position: relative;
			padding: 30rpx;
			min-height: 70vh;

			.list-block {
				display: flex;
				flex-direction: row;
				flex-wrap: wrap;
				margin-bottom: 30rpx;


				.info-list {
					background: #fff;
					margin-top: 20rpx;
					border-radius: 20rpx;
					width: calc((100% - 20rpx) / 2);
					margin-right: 20rpx;

					.info-item {
						width: 100%;
						display: flex;
						flex-direction: column;

						.img {
							width: 100%;
							height: 360rpx;
							border-radius: 20rpx 20rpx 0 0;
						}

						.describe-item {
							padding: 30rpx;

							.name {
								font-size: 32rpx;
								font-weight: bold;
								margin-bottom: 15rpx;
								overflow: hidden;
								text-overflow: ellipsis;
								white-space: nowrap;
							}

							.describe {
								color: #828282;
								font-size: 28rpx;
								margin-bottom: 15rpx;
								overflow: hidden;
								text-overflow: ellipsis;
								white-space: nowrap;
							}

							.wage {
								color: #157DFA;
								font-weight: bold;
								font-size: 30rpx;

								.txt {
									font-size: 38rpx;
									margin-right: 10rpx;
								}
							}
						}
					}
				}

				.info-list:nth-child(2n) {
					margin-right: 0;
				}
			}

			.empty {
				display: flex;
				justify-content: center;
			}
		}
	}
</style>